﻿myApp.controller("NewsCtrl", function ($scope, $post, $http, $resource, $routeParams, $restUrls, $rootScope, $location) {


    $scope.type  = false;
    $scope.change_type = function(){
        $scope.type = !$scope.type;
    }

    $scope.page = 0;


    $scope.list = [];
    $scope.distance = 0;
    $scope.paginating = false;
    $scope.enabled = true;

    $scope.loadList = function () {
        if (!$scope.enabled || true === $scope.paginating)
            return;

        var parameters = {
            pageNum: $scope.page++,
            pageSize: 20
        };

        $scope.paginating = true;

        $resource($restUrls["getMyPages"] + '&pageNum=:pageNum&pageSize=:pageSize').get(parameters).$promise.then(function (data) {


            for (var i = 0; i < data.data.length; i++) {
                $scope.list.push(data.data[i]);
            }
            $scope.enabled = data.data.length > 0;
            $scope.paginating = false;

        });

    };

    $scope.loadList();


    $scope.loadFeedback = function () {


        $resource($restUrls["getFeedbackList"] ).get({}).$promise.then(function (data) {


            $scope.feedbacks = data.data;

        });

    };

    $scope.loadFeedback();

    $scope.feedback = function () {

        $post($restUrls["feedback"],
            {
                message: $('.sc_box').text()
            })
            .success(function (result) {
                $('.sc_box').text('');
                $scope.loadFeedback();
            }).error(function (data, status, headers, config) {
        });

    };

});
